package cn.wolfcode.controller;

import cn.wolfcode.domain.SystemDictionary;
import cn.wolfcode.qo.QueryObject;
import cn.wolfcode.service.ISystemDictionaryService;
import cn.wolfcode.util.RequiredPermission;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;

@Controller
@RequestMapping("/systemDictionary")
public class SystemDictionaryController {
    @Autowired
    private ISystemDictionaryService systemDictionaryService;
    @RequestMapping("/list")
    @RequiredPermission(name="部门显示",expression ="systemDictionary:list")
    public String list(@ModelAttribute("qo") QueryObject qo, Model model){
        PageInfo<SystemDictionary> pageInfo = systemDictionaryService.query(qo);
        model.addAttribute("pageInfo",pageInfo);
        return "/systemDictionary/list";
    }
    @RequestMapping("/delete")
    @RequiredPermission(name="部门删除",expression ="systemDictionary:delete")
    public String delete(Long id){
        if (id != null) {
            systemDictionaryService.delete(id);
        }
        return "redirect:/systemDictionary/list";
    }
    @RequestMapping("/saveOrUpdate")
    @RequiredPermission(name="部门新增/编辑",expression ="systemDictionary:saveOrUpdate")
    public String saveOrUpdate(SystemDictionary systemDictionary){
        if (systemDictionary.getId() != null) {
            systemDictionaryService.update(systemDictionary);
        } else {
            systemDictionaryService.insert(systemDictionary);
        }
        return "redirect:/systemDictionary/list";
    }
}
